package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlMessageRead entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlMessageRead
 * @author MyEclipse Persistence Tools
 */

public class MdlMessageReadDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlMessageReadDAO.class);
	// property constants
	public static final String USERIDFROM = "useridfrom";
	public static final String USERIDTO = "useridto";
	public static final String SUBJECT = "subject";
	public static final String FULLMESSAGE = "fullmessage";
	public static final String FULLMESSAGEFORMAT = "fullmessageformat";
	public static final String FULLMESSAGEHTML = "fullmessagehtml";
	public static final String SMALLMESSAGE = "smallmessage";
	public static final String NOTIFICATION = "notification";
	public static final String CONTEXTURL = "contexturl";
	public static final String CONTEXTURLNAME = "contexturlname";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEREAD = "timeread";

	public void save(MdlMessageRead transientInstance) {
		log.debug("saving MdlMessageRead instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlMessageRead persistentInstance) {
		log.debug("deleting MdlMessageRead instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlMessageRead findById(java.lang.Long id) {
		log.debug("getting MdlMessageRead instance with id: " + id);
		try {
			MdlMessageRead instance = (MdlMessageRead) getSession().get(
					"idv.loveloser.dao.MdlMessageRead", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlMessageRead instance) {
		log.debug("finding MdlMessageRead instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlMessageRead")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlMessageRead instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlMessageRead as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByUseridfrom(Object useridfrom) {
		return findByProperty(USERIDFROM, useridfrom);
	}

	public List findByUseridto(Object useridto) {
		return findByProperty(USERIDTO, useridto);
	}

	public List findBySubject(Object subject) {
		return findByProperty(SUBJECT, subject);
	}

	public List findByFullmessage(Object fullmessage) {
		return findByProperty(FULLMESSAGE, fullmessage);
	}

	public List findByFullmessageformat(Object fullmessageformat) {
		return findByProperty(FULLMESSAGEFORMAT, fullmessageformat);
	}

	public List findByFullmessagehtml(Object fullmessagehtml) {
		return findByProperty(FULLMESSAGEHTML, fullmessagehtml);
	}

	public List findBySmallmessage(Object smallmessage) {
		return findByProperty(SMALLMESSAGE, smallmessage);
	}

	public List findByNotification(Object notification) {
		return findByProperty(NOTIFICATION, notification);
	}

	public List findByContexturl(Object contexturl) {
		return findByProperty(CONTEXTURL, contexturl);
	}

	public List findByContexturlname(Object contexturlname) {
		return findByProperty(CONTEXTURLNAME, contexturlname);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimeread(Object timeread) {
		return findByProperty(TIMEREAD, timeread);
	}

	public List findAll() {
		log.debug("finding all MdlMessageRead instances");
		try {
			String queryString = "from MdlMessageRead";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlMessageRead merge(MdlMessageRead detachedInstance) {
		log.debug("merging MdlMessageRead instance");
		try {
			MdlMessageRead result = (MdlMessageRead) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlMessageRead instance) {
		log.debug("attaching dirty MdlMessageRead instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlMessageRead instance) {
		log.debug("attaching clean MdlMessageRead instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}